package com.logistics.erp.entity.model;

import com.logistics.erp.entity.domain.ErpFlow;
import com.logistics.material.entity.model.MaterialBackSave;
import com.logistics.material.entity.model.MaterialPickSave;
import com.logistics.utils.bean.SaveBasic;
import com.logistics.utils.constants.Constants;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

@Data
public class ErpInvBillSave extends SaveBasic {

    private String erpInvBillCode;
    private Integer priority;
    private String wcCode;
    private String wcName;
    private String deptCode;
    private String deptName;
    private String endLocation;
    private String endLocationName;
    private String locationArea;
    private Integer lackMaterialStatus;
    private String erpInvBillType;

    public static ErpInvBillSave build(MaterialPickSave save, ErpFlow flow, Integer lackMaterialStatus, Integer priority, String locationArea) {
        ErpInvBillSave erpInvBillSave = new ErpInvBillSave();
        erpInvBillSave.setErpInvBillCode(save.getErpInvBillCode());
        erpInvBillSave.setCreateDepCode(save.getCreateDepCode());
        erpInvBillSave.setCreator(save.getCreator());
        erpInvBillSave.setCreateTime(save.getCreateTime());
        erpInvBillSave.setCreateOrgCode(save.getCreateOrgCode());
        erpInvBillSave.setUpdater(save.getUpdater());
        erpInvBillSave.setUpdateTime(save.getUpdateTime());
        erpInvBillSave.setPriority(priority);
        erpInvBillSave.setWcCode(flow.getWcCode());
        erpInvBillSave.setEndLocation(StringUtils.isNotNull(flow.getEndLocation()) ? flow.getEndLocation() : flow.getWcCode());
        erpInvBillSave.setEndLocationName(flow.getEndLocationName());
        erpInvBillSave.setWcName(flow.getWcName());
        erpInvBillSave.setDeptCode(flow.getDeptCodeWc());
        erpInvBillSave.setDeptName(flow.getDeptNameWc());
        erpInvBillSave.setLackMaterialStatus(lackMaterialStatus);
        erpInvBillSave.setLocationArea(locationArea);
        erpInvBillSave.setErpInvBillType(save.getErpInvBillType());
        return erpInvBillSave;
    }

    public static  ErpInvBillSave build(MaterialBackSave save, String endLocation) {
        ErpInvBillSave erpInvBillSave = new ErpInvBillSave();
        erpInvBillSave.setErpInvBillType(Constants.PICK_TYPE_BACK);
        erpInvBillSave.setErpInvBillCode(save.getErpInvBillCode());
        erpInvBillSave.setWcCode(endLocation);
        erpInvBillSave.setEndLocation(endLocation);
        return erpInvBillSave;
    }
}
